package com.ruoyi.web.controller.huashu;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.Poster;
import com.ruoyi.system.domain.vo.business.PosterAddDto;
import com.ruoyi.system.domain.vo.business.PosterSelectListDto;
import com.ruoyi.system.domain.vo.business.PosterUpdateDto;
import com.ruoyi.system.service.IPosterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.rmi.ServerException;
import java.util.List;

/**
 * 专题管理Controller
 *
 * @author ruoyi
 * @date 2024-02-26
 */
@Api(tags = {"（华数）专题管理"})
@Controller
@RequestMapping("TV/poster")
public class HuashuPosterController extends BaseController {
    private String prefix = "/poster";

    @Autowired
    private IPosterService posterService;

    //@RequiresPermissions("system:poster:view")
    @GetMapping()
    public String poster() {
        return prefix + "/poster";
    }

    /**
     * 查询专题管理列表
     */
    @ApiOperation("查询专题管理列表")
    //@RequiresPermissions("system:poster:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PosterSelectListDto poster) {
        startPage();
        List<Poster> list = posterService.selectPosterList(poster);
        return getDataTable(list);
    }

    /**
     * 导出专题管理列表
     */
    @ApiOperation("导出专题管理列表")
    //@RequiresPermissions("system:poster:export")
    @Log(title = "专题管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PosterSelectListDto poster) {
        List<Poster> list = posterService.selectPosterList(poster);
        ExcelUtil<Poster> util = new ExcelUtil<Poster>(Poster.class);
        return util.exportExcel(list, "专题管理数据");
    }

    /**
     * 新增专题管理
     */
//    @ApiOperation("新增专题管理")
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存专题管理
     */
    @ApiOperation("新增专题管理")
    //@RequiresPermissions("system:poster:add")
    @Log(title = "专题管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PosterAddDto addDto) throws ServerException {
        Poster poster = new Poster();
        BeanUtil.copyProperties(addDto, poster);
        return toAjax(posterService.insertPoster(poster));
    }

    /**
     * 修改专题管理
     */
//    @ApiOperation("修改专题管理")
    //@RequiresPermissions("system:poster:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        Poster poster = posterService.selectPosterById(id);
        mmap.put("poster", poster);
        return prefix + "/edit";
    }

    /**
     * 修改保存专题管理
     */
    @ApiOperation("修改专题管理")
    //@RequiresPermissions("system:poster:edit")
    @Log(title = "专题管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PosterUpdateDto updateDto) throws ServerException {
        Poster poster = new Poster();
        BeanUtil.copyProperties(updateDto, poster);
        return toAjax(posterService.updatePoster(poster));
    }

    /**
     * 删除专题管理
     */
    @ApiOperation("删除专题管理-- 多个id用,拼接")
    //@RequiresPermissions("system:poster:remove")
    @Log(title = "专题管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(posterService.deletePosterByIds(ids));
    }
}
